<%@page import="org.apache.commons.lang.StringUtils"%>
<%@page import="org.apache.commons.lang.time.DateFormatUtils"%>
<%@page import="org.springframework.util.CollectionUtils"%>
<%@page import="java.util.Collection"%>
<%@ include file="../common/common_include.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	SettingForm form = (SettingForm)request.getAttribute("command");
	List<TsUser> userList = (List<TsUser>)request.getAttribute("userList");
	
	String userId  = (null!=form.getUserId())?form.getUserId():"";
	String userName  = (null!=form.getUserName())?form.getUserName():"";
	String siteId = (null!=form.getSiteId())?form.getSiteId():"";
	String deptId  = (null!=form.getDeptId())?form.getDeptId():"";
	String enabled  = (null!=form.getEnabled())?form.getEnabled():"";
	
	String createDateBegin  = (null!=form.getCreateDateBegin())?form.getCreateDateBegin():"";
	String createDateEnd  = (null!=form.getCreateDateEnd())?form.getCreateDateEnd():"";
%>

<div class="userListWrap" id="userListWrap">
	
	<form id="userListForm">
        <div class="form-item">
    		<label for="userId">用户ID:</label>
    		<input class="easyui-validatebox" type="text" name="userId" data-options="" value="<%=userId%>"/>
        </div>
        <div class="form-item">
    		<label for="userName">用户姓名:</label>
    		<input class="easyui-validatebox" type="text" name="userName" data-options="" value="<%=userName%>"/>
        </div>
        <div class="form-item">
    		<label for="siteId">所属站点:</label>
    		<input class="easyui-validatebox" type="text" name="siteId" data-options="" value="<%=siteId%>"/>
        </div>
        <%-- <div class="form-item">
    		<label for="deptId">所属部门:</label>
    		<input class="easyui-validatebox" type="text" name="deptId" data-options="" value="<%=deptId%>"/>
        </div> --%>
        <div class="form-item">
    		<label for="deptId">使用状态:</label>
			<select name="enabled" form="enabled">
				<option value="">全部</option>
				<option value="0" <%=enabled.equalsIgnoreCase("0")?"selected=selected":""%>>未启用</option>
				<option value="1" <%=enabled.equalsIgnoreCase("1")?"selected=selected":""%>>已启用</option>
			</select>    		
        </div>
        <div class="form-item form-item-two">
    		<label for="deptId">创建时间:</label>
    		<input id="createDateBegin" name="createDateBegin" type="text" class="easyui-datebox">--
    		<input id="createDateEnd" name="createDateEnd" type="text" class="easyui-datebox">
        </div>
        
        <div class="form-item form-item">
    		<a href="javascript:XF.Setting.listUserSearch()" class="input-btn-microsoft input-btn-microsoft-24">搜索</a>
        </div>
        
    </form>

    <table id="userListTable" class="easyui-datagrid"  title="" >
        <thead>
    		<tr>
    			<th data-options="field:'select',width:80,align:'center',checkbox:'true'"><input type="checkbox"></th>
    			<th data-options="field:'userId',width:150" orderByField='userId' >
					<a class="order-field" href="javascript:XF.Setting.listUserSearch('userId')" >用户ID</a>
					<%
						if(StringUtils.isNotBlank(form.getOrderByField()) && StringUtils.isNotBlank(form.getOrderByMode())){
							if("userId".equalsIgnoreCase(form.getOrderByField())){
								if("asc".equalsIgnoreCase(form.getOrderByMode())){
									%><span class="px t" orderByMode='desc'>&nbsp;</span><%
								}else if("desc".equalsIgnoreCase(form.getOrderByMode())){
									%><span class="px d" orderByMode='asc'>&nbsp;</span><%
								}else{
									%><span class="px" orderByMode='asc'>&nbsp;</span><%
								}
							}else{
								%><span class="px" orderByMode='asc'>&nbsp;</span><%
							}
						}else{
							%><span class="px" orderByMode='asc'>&nbsp;</span><%
						}
					%>
				</th>
    			<th data-options="field:'userName',width:80" orderByField='userName' >
					<a class="order-field" href="javascript:XF.Setting.listUserSearch('userName')" >用户姓名</a>
					<%
						if(StringUtils.isNotBlank(form.getOrderByField()) && StringUtils.isNotBlank(form.getOrderByMode())){
							if("userName".equalsIgnoreCase(form.getOrderByField())){
								if("asc".equalsIgnoreCase(form.getOrderByMode())){
									%><span class="px t" orderByMode='desc'>&nbsp;</span><%
								}else if("desc".equalsIgnoreCase(form.getOrderByMode())){
									%><span class="px d" orderByMode='asc'>&nbsp;</span><%
								}else{
									%><span class="px" orderByMode='asc'>&nbsp;</span><%
								}
							}else{
								%><span class="px" orderByMode='asc'>&nbsp;</span><%
							}
						}else{
							%><span class="px" orderByMode='asc'>&nbsp;</span><%
						}
					%>
				</th>
    			<th data-options="field:'siteId',width:80" orderByField='siteId' >
					<a class="order-field" href="javascript:XF.Setting.listUserSearch('siteId')" >所属站点</a>
					<%
						if(StringUtils.isNotBlank(form.getOrderByField()) && StringUtils.isNotBlank(form.getOrderByMode())){
							if("siteId".equalsIgnoreCase(form.getOrderByField())){
								if("asc".equalsIgnoreCase(form.getOrderByMode())){
									%><span class="px t" orderByMode='desc'>&nbsp;</span><%
								}else if("desc".equalsIgnoreCase(form.getOrderByMode())){
									%><span class="px d" orderByMode='asc'>&nbsp;</span><%
								}else{
									%><span class="px" orderByMode='asc'>&nbsp;</span><%
								}
							}else{
								%><span class="px" orderByMode='asc'>&nbsp;</span><%
							}
						}else{
							%><span class="px" orderByMode='asc'>&nbsp;</span><%
						}
					%>
				</th>
    			<%-- <th data-options="field:'deptId',width:100" orderByField='deptId' >
					<a class="order-field" href="javascript:XF.Setting.listUserSearch('deptId')" >所属部门</a>
					<%
						if(StringUtils.isNotBlank(form.getOrderByField()) && StringUtils.isNotBlank(form.getOrderByMode())){
							if("deptId".equalsIgnoreCase(form.getOrderByField())){
								if("asc".equalsIgnoreCase(form.getOrderByMode())){
									%><span class="px t" orderByMode='desc'>&nbsp;</span><%
								}else if("desc".equalsIgnoreCase(form.getOrderByMode())){
									%><span class="px d" orderByMode='asc'>&nbsp;</span><%
								}else{
									%><span class="px" orderByMode='asc'>&nbsp;</span><%
								}
							}else{
								%><span class="px" orderByMode='asc'>&nbsp;</span><%
							}
						}else{
							%><span class="px" orderByMode='asc'>&nbsp;</span><%
						}
					%>
				</th> --%>
    			<th data-options="field:'enabled',width:70" orderByField='enabled' >
					<a class="order-field" href="javascript:XF.Setting.listUserSearch('enabled')" >使用状态</a>
					<%
						if(StringUtils.isNotBlank(form.getOrderByField()) && StringUtils.isNotBlank(form.getOrderByMode())){
							if("enabled".equalsIgnoreCase(form.getOrderByField())){
								if("asc".equalsIgnoreCase(form.getOrderByMode())){
									%><span class="px t" orderByMode='desc'>&nbsp;</span><%
								}else if("desc".equalsIgnoreCase(form.getOrderByMode())){
									%><span class="px d" orderByMode='asc'>&nbsp;</span><%
								}else{
									%><span class="px" orderByMode='asc'>&nbsp;</span><%
								}
							}else{
								%><span class="px" orderByMode='asc'>&nbsp;</span><%
							}
						}else{
							%><span class="px" orderByMode='asc'>&nbsp;</span><%
						}
					%>
				</th>
    			
    			
 				<th data-options="field:'date',width:100" orderByField='createDate' >
					<a class="order-field" href="javascript:XF.Setting.listUserSearch('createDate')" >创建时间</a>
					<%
						if(StringUtils.isNotBlank(form.getOrderByField()) && StringUtils.isNotBlank(form.getOrderByMode())){
							if("createDate".equalsIgnoreCase(form.getOrderByField())){
								if("asc".equalsIgnoreCase(form.getOrderByMode())){
									%><span class="px t" orderByMode='desc'>&nbsp;</span><%
								}else if("desc".equalsIgnoreCase(form.getOrderByMode())){
									%><span class="px d" orderByMode='asc'>&nbsp;</span><%
								}else{
									%><span class="px" orderByMode='asc'>&nbsp;</span><%
								}
							}else{
								%><span class="px" orderByMode='asc'>&nbsp;</span><%
							}
						}else{
							%><span class="px" orderByMode='asc'>&nbsp;</span><%
						}
					%>
				</th>
    			
    			
    			<th data-options="field:'roles',width:200">角色</th>
    			<th data-options="field:'opr',width:100">操作</th>
    		</tr>
        </thead>
        <tbody>
        	<%
        		if(!CollectionUtils.isEmpty(userList)){
        			for(TsUser user:userList){
        				%>
       					 <tr s="<%=user.getUserid() %>">
			    			<td></td>
			    			<td><i s="<%=user.getUserid()%>"/><%=user.getUserid() %></td>
			    			<td><%=user.getUsername() %></td>
			    			<td><%=user.getSiteid() %></td>
			    			<%-- <td><%= StringUtils.isNotBlank(user.getDeptid())?user.getDeptid():""  %></td> --%>
			    			<td><%=user.getEnableHanzi()%></td>
			    			<td><%=null!=user.getCreatedate()?DateFormatUtils.format(user.getCreatedate().getTime(), "yyyy-MM-dd"):"" %></td>
			    			<td><a class="aText" title="<%=StringUtils.isNotBlank(user.getRoleDescs())?user.getRoleDescs():"" %>"><%=StringUtils.isNotBlank(user.getRoleDescs())?user.getRoleDescs():"" %></a></td>
			    			<td>
			    				<a class="inLink" href="javascript:XF.Setting.editUser('<%=user.getUserid()%>')"><span>编辑</span></a>
			    				<a href="javascript:XF.Setting.deleteUser('<%=user.getUserid()%>')"><span>删除</span></a>
			    			</td>
			    		</tr>
        				<%
        			}
        		}
        	%>
    	</tbody>
    </table>
    <div class="pagination">
		<monggoTag:pagination 
		href="listUser_search"
		pageSize="<%=form.getPageSize()%>" 
		totalRecord="<%=form.getTotalRecord() %>" 
		currentPage="<%=form.getPageNum() %>">
		</monggoTag:pagination> 
	</div>
</div>
<script>
	$('#userListTable').datagrid(); 
	$("#createDateBegin").datebox({
		formatter:XF.dateFormatter,
		parser:XF.dateParse
	});
	<%
		if(StringUtils.isNotBlank(createDateBegin)){
			%>
				$("#createDateBegin").datebox("setValue","<%=createDateBegin%>");
			<%
		}
	%> 
	
	$("#createDateEnd").datebox({
		formatter:XF.dateFormatter,
		parser:XF.dateParse
	});
	
	<%
	if(StringUtils.isNotBlank(createDateEnd)){
		%>
			$("#createDateEnd").datebox("setValue","<%=createDateEnd%>");
		<%
	}
%> 
</script>